package com.aabte.design.pattern.creational.prototype.mail;

public class MailUtilTest {

    public static void main(String[] args) throws CloneNotSupportedException {

        // test1();
        test2();

    }

    public static void test1(){
        Mail mail = new Mail();

        mail.setContent("初始化模板");

        for (int i = 0; i < 10; i++) {
            mail.setName("姓名" + i);
            mail.setEmailAddress(mail.getName() + "@example.com");
            mail.setContent("恭喜您，中奖了！");
            MailUtil.sendMail(mail);
        }

        MailUtil.saveOriginMailRecord(mail);
    }

    public static void test2() throws CloneNotSupportedException {
        Mail mail = new Mail();

        mail.setContent("初始化模板");

        for (int i = 0; i < 10; i++) {
            Mail mailTemp = (Mail)mail.clone();
            mailTemp.setName("姓名" + i);
            mailTemp.setEmailAddress(mail.getName() + "@example.com");
            mailTemp.setContent("恭喜您，中奖了！");
            MailUtil.sendMail(mailTemp);
        }

        MailUtil.saveOriginMailRecord(mail);
    }

}
